package glemipsc.instructions;

import glemipsc.Address;
import glemipsc.Function;
import glemipsc.GLEMipsC;
import glemipsc.Type;
import glemipsc.implementations.Argument;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Not extends BaseInstruction implements Serializable, Instruction, Expression {
	private Expression op;
	private Address addr;
	
	public Not(Expression op) {
		this.op = op;
	}
	
	public Expression getOperand(int index) {
		if (index == 0)
			return op;
		return null;
	}
	
	public int getNumberOfOperands() {
		return 1;
	}

	public int getSize() {
		return 0;
	}

	public Type getType() {
		return op.getType();
	}

	public int getImmediateValue() {
		return op.getImmediateValue() == 0 ? 1 : 0;
	}

	public boolean isImmediate() {
		return op.isImmediate();
	}

	public Address getStoreAddress() {
		return addr;
	}

	public int getStoredSize() {
		// TODO Auto-generated method stub
		return 0;
	}

	public boolean isStored() {
		return !isImmediate();
	}

	public void setStoreAddress(Address addr) {
		this.addr = addr;
	}

	public void computeInstruction(Argument result, List<glemipsc.implementations.Instruction> instructions, Function func) {
		glemipsc.implementations.Implementation impl = GLEMipsC.compiler.getEnvironment().implementation;
		op.computeInstruction(result, instructions, func);
		instructions.add(impl.getXor(result, result, impl.getImmediate(1)));
	}

}
